package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.ArticleConstants;
import com.heima.common.constants.WmNewsMessageConstants;
import com.heima.model.search.vos.SearchArticleVo;
import com.heima.search.service.SyncArticleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SyncArticleListener {
    @Autowired
    private SyncArticleService syncArticleService;

    @KafkaListener(topics = ArticleConstants.ARTICLE_ES_SYNC_TOPIC)
    public void onMessageSync(String message) {
        if (StringUtils.isNotEmpty(message)) {
            SearchArticleVo vo = JSON.parseObject(message, SearchArticleVo.class);
            syncArticleService.SyncArticle(vo);
        }
    }
}
